using System;
using System.Collections.Generic;
using System.Text;
using Ent.Web.Helper;
using System.Configuration;
using System.Web;
namespace Ent.Web.Helper
{
    public class Priviledge
    {
        private static Dictionary<string, Dictionary<string, string>> _properties = null;
        static Dictionary<string, Dictionary<string, string>> Properties
        {
            get
            {
                if (_properties == null)
                    Ent.Web.Helper.Priviledge.Init(ConfigurationManager.AppSettings.Get("Priviledge"));
                return _properties;
            }
        }
        public static void Init(string path)
        {
            path = HttpRuntime.AppDomainAppPath + "/" + path;
            if (_properties == null)
            {
                _properties = new Dictionary<string, Dictionary<string, string>>();
                XMLHelper _xml = new XMLHelper(path);
                string root = "//Vibzworld/feature";
                string[] names = _xml.GetAttributesOfAllNodes(root, "name");
                foreach (string name in names)
                {
                    string xpath = root + "[@name='" + name + "']";
                    _properties.Add(name, _xml.GetNameValuePair(xpath, "property", "name", "value"));
                }
            }
        }
        public static Dictionary<string, string> GetProperties(string featureName)
        {
            if (Properties.ContainsKey(featureName))
                return Properties[featureName];
            else return new Dictionary<string, string>();
        }
    }
}
